package mashuaiproject.mashuaiproject.serivce;

import mashuaiproject.mashuaiproject.mapper.DelMapper;
import mashuaiproject.mashuaiproject.mapper.FabulousMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class DelSerivce {
    @Autowired
    private DelMapper delMapper;
    public int delFabuloud(Integer delId, Integer id) {
        //id是用户的id...delid是删评论的id
        //先查找出该帖子是否有点赞
        Integer fabulousUp=delMapper.selectFabulousUp(delId);
        Integer fabulousDown=delMapper.selectFabulousDown(delId);
        if(fabulousUp!=0 || fabulousDown!=0){
            //就删除点赞信息：
            int delFabulous=delMapper.delFabuloud(delId,id);//删除相关点赞信息
        }
        //查找出评论是不是有子评论
        Integer commentSonCount=delMapper.selectCommentSonCout(delId);
        if(commentSonCount!=0){
            //删除这个话题的子评论
            for (int i=0;i<commentSonCount;i++){
                int delCommentSon=delMapper.delCommentSon(delId);
                System.err.println("第"+i+"次循环子评论删除");
            }
        }
        //找出是否有回复通知内容
        Integer notification=delMapper.selectNotifi(delId);
        if(notification!=0){
            for (int i=0;i<notification;i++){
                int delNotifi=delMapper.delNotifis(delId);
                System.err.println("第"+i+"次循环删除回复通知");
            }
        }
        //在删除这个评论：
        int delComment=delMapper.delComments(delId,id);
        return 0;
    }
}
